package com.ashbur.rookie.admin.controller;

import com.ashbur.rookie.admin.service.FriendLinkService;
import com.ashbur.rookie.api.BaseController;
import com.ashbur.rookie.api.controller.admin.FriendLinkMngControllerApi;
import com.ashbur.rookie.common.grace.result.GraceJSONResult;
import com.ashbur.rookie.pojo.bo.SaveFriendLinkBO;
import com.ashbur.rookie.pojo.mo.FriendLinkMO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
public class FriendLinkMngController extends BaseController implements FriendLinkMngControllerApi {

    final static Logger logger = LoggerFactory.getLogger(FriendLinkMngController.class);

    @Autowired
    private FriendLinkService friendLinkService;


    @Override
    public GraceJSONResult saveOrUpdateFriendLink(SaveFriendLinkBO saveFriendLinkBO) {

        // 保存到MongoDB
        FriendLinkMO friendLinkMO = new FriendLinkMO();
        BeanUtils.copyProperties(saveFriendLinkBO, friendLinkMO);
        friendLinkMO.setCreateTime(new Date());
        friendLinkMO.setUpdateTime(new Date());

        friendLinkService.saveOrUpdateFriendLink(friendLinkMO);

        return GraceJSONResult.ok();
    }
    @Override
    public GraceJSONResult getFriendLinkList() {
        List<FriendLinkMO> list = friendLinkService.queryFriendLinkList();
        return GraceJSONResult.ok(list);
    }


    @Override
    public GraceJSONResult deleteFriendLink(String linkId) {
        friendLinkService.deleteFriendLink(linkId);
        return GraceJSONResult.ok();
    }

    @Override
    public GraceJSONResult getPortalFriendLinkList() {
        List<FriendLinkMO> list = friendLinkService.queryPortalFriendLinkList();
        return GraceJSONResult.ok(list);
    }



}

